<template>
  <span class="score">
    <!-- 同时存在多个for循环且循环同一数据，key值不能相同 -->
    <div v-for='(item, index) in className' :key="index + 10000">{{ item }}</div>
    <i v-for='(item, index) in className' :key="index" :class='item'></i>
  </span>
</template>
<script>
export default {
  props: {
    level: Number
  },
  data () {
    return {
      className: []
    }
  },
  created() {
    this.scoreFun(this.level);
  },
  mounted() {
    
  },
  methods: {
    scoreFun: function(num) {
      for(let i = 0; i < 5; i ++) {
        if(i < num) this.className[i] = 'star-full';
        else this.className[i] = 'star-empty';
      }
    }
  }
};
</script>
<style lang='scss' scoped>
.score{
  display: inline-block;
  width: 100%;
  height: 1.333rem;
  padding: 0.347rem 0;
  font-size: 0;
  box-sizing: border-box;
  & > i{
    display: inline-block;
    vertical-align: middle;
    width: .64rem;
    height: .64rem;
    background-repeat: no-repeat;
    background-size: 80%;
    background-position: 0;
  }
  .star-full{
    background-image: url();
  }
  .star-empty{
    background-image: url();
  }
}
</style>